package com.copa.ums.modules.ums.controller;

import com.copa.ums.common.vo.ResponseVo;
import com.copa.ums.modules.ums.model.UmsResourceCategory;
import com.copa.ums.modules.ums.service.UmsResourceCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author copa
 * @since 2022-10-31
 */
@RestController
@Api(tags = "资源分类管理")
@Tag(name = "资源分类管理",description = "资源分类管理")
@RequestMapping("resourceCategory")
public class UmsResourceCategoryController {

    @Resource
    private UmsResourceCategoryService resourceCategoryService;

    @ApiOperation("查询所有后台资源分类")
    @GetMapping("listAll")
    public ResponseVo<List<UmsResourceCategory>> listAll() {
        return resourceCategoryService.listAll();
    }

    @ApiOperation("添加后台资源分类")
    @PostMapping("create")
    public ResponseVo<String> create(@RequestBody UmsResourceCategory umsResourceCategory) {
        return resourceCategoryService.create(umsResourceCategory);
    }

    @ApiOperation("修改后台资源分类")
    @PostMapping(value = "update/{categoryId}")
    public ResponseVo<String> update(@PathVariable("categoryId") Long categoryId,
                                     @RequestBody UmsResourceCategory umsResourceCategory) {
        umsResourceCategory.setId(categoryId);
        return resourceCategoryService.updateById(umsResourceCategory)
                ? ResponseVo.success(null)
                : ResponseVo.failed();
    }

    @ApiOperation("根据id删除后台资源分类")
    @PostMapping( "delete/{categoryId}")
    public ResponseVo<String> delete(@PathVariable("categoryId") Long categoryId) {
        return resourceCategoryService.removeById(categoryId)
                ? ResponseVo.success(null)
                : ResponseVo.failed();
    }
}

